package com.yozinga.processor;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;

import com.yozinga.util.SharedData;

import android.content.Context;
import android.util.Log;

public class BusinessTypeProcessor {

	Context mContext;
	SharedData mSharedData;
	String mScreenName;
	public BusinessTypeProcessor(SharedData sharedData,String screenName) {
		mScreenName = screenName;
		mSharedData = sharedData;
		/*mContext = context;
		if(mContext!=null){
			Log.i("Today","Context not null");
			mSharedData = new SharedData(mContext);
		}else{
			Log.i("Today","Context  null");
		}*/
	}

	//HashMap<String,HashMap<String, String>> businessTypeHashMap = new HashMap<String,HashMap<String, String>>();
	HashMap<String,String> businessTypeHashMap = new HashMap<String,String>();
	public HashMap<String,String/*HashMap<String, String>*/> getBusinessTypes(String businessTypesResponse){

		JSONArray businessTypeArray;
		try {
			businessTypeArray = new JSONArray(businessTypesResponse);
			for (int i = 0; i < businessTypeArray.length(); i++) {

				String businessName  = businessTypeArray.getJSONObject(i).getString("Name");
				//String tempBusinessName = businessTypeArray.getJSONObject(i).getString("Name");
				String id = businessTypeArray.getJSONObject(i).getString("Id");
				if(businessName.contains("TH")){
					businessName.replace("TH", "Travel and Hotels");
					//tempBusinessName = "TH";
				}
				/*if(businessName.contains("-")){
					businessName = businessName.substring(0,businessName.indexOf("-"));
				}*/

				//businessName = businessName.toLowerCase();

				
				//tempBusinessName = tempBusinessName.toLowerCase();
				/*HashMap<String,String> tempHashMap;
				if(!businessTypeHashMap.containsKey(businessName) ){
					businessTypeHashMap.put(businessName, new HashMap<String, String>());
					tempHashMap = businessTypeHashMap.get(businessName);
					tempHashMap.put(tempBusinessName, id);
					Log.i("Today","if TempHash sizi s:"+tempBusinessName);
					businessTypeHashMap.put(businessName,  tempHashMap);

				}else{
					tempHashMap = businessTypeHashMap.get(businessName);
					tempHashMap.put(tempBusinessName, id);
					Log.i("Today","else TempHash sizi s:"+tempBusinessName);
					businessTypeHashMap.put(businessName,  tempHashMap);
				}*/
				
				if(mScreenName.equals("HomeScreen")){
					businessTypeHashMap.put(businessName, id);
					
					Log.i("Today","businessName : "+businessName);
					Log.i("Today","id : "+id);
					
					//Store Business Type Ids for Filter in Favourites
					mSharedData.setBusinessTypes(businessName, id);
				}else{
					
					//SubCategory Names are Lower Case letters
					businessTypeHashMap.put(businessName.toLowerCase(), id);
				}
					

			}

		} catch (JSONException e) {
			e.printStackTrace();
		}

		return businessTypeHashMap;
	}
}
